<script type="text/javascript">
    function TzzglManagerCtrl($scope, $http, modalService, CtrlUtil, $element, UploadService) {
        var ctrl = this
        CtrlUtil.build(ctrl, ':root/tgb/list')
        this.query = function () {
            ctrl.entities && (ctrl.entities.content = {})
            var p = CtrlUtil.getQueryParams(ctrl)
            $http.post(':root/tgb/list', p).success(function (r) {
                ctrl.entities = r;
            })
        }
        this.edit = function (item) {
            ctrl.add(item)
        }
        this.del = function (item) {
            modalService.confirm({
                content: '确定要删除团干部' + item.xm + '吗?',
                result: item
            }).then(function (r) {
                $http.post(':root/tgb/deleteTgb', r).success(function (R) {
                    modalService.succ('删除成功', 1500)
                    ctrl.query()
                })
            })

        }
        this.add = function (item) {
            var content = $element.find('[template]>[edit]').clone()
            var title = $element.find('[template]>[edit-title]').clone()
            var result = item,
            result = result || {
                    tgb : 1
                };

            if (item) {
                //查询教师信息
                $http.post(':root/tgb/teacher', {gh: item.xh}).success(function (r) {
                    result.teacher = r;
                });
                result.showBranch = true;
            }

            modalService.confirm({
                title: title,
                content: content,
                size: 'lg',
                titleCls: '',
                result: result,
                $scope: $scope,
                validator: function (r) {

                }
            }, {
                backdrop: false
            }).then(function (r) {
                $http.post(':root/tgb/addTgb', r).success(function (R) {
                    modalService.succ(item ? '修改成功' : '添加成功', 1500);
                    ctrl.query();
                })
            })
        }
    }

</script>
<div ng-controller="TzzglManagerCtrl as ctrl" ng-init="ctrl.query()">
    <!-- Search area -->
    <div class="panel panel-cys">
        <div class="panel-heading">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-search"></span> 信息查询
            </h3>
        </div>
        <div class="panel-body">
            <div class="container-fluid">
                <form class="form-horizontal">
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <input placeholder="学号/姓名" ng-model="ctrl.ghQueryParam" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <select chosen ng-model="ctrl.lxQueryParam" class="form-control">
                                <option value="">团干部</option>
                                <option value="0">兼职</option>
                                <option value="1">专职</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group col-md-4 remove-margin-horizontal">
                        <div class="col-md-10 col-md-offset-1">
                            <div class="form-control-static">&nbsp;</div>
                        </div>
                    </div>
                </form>
                <div class="row pull-right">
                    <div class="col-md-12">
                        <button ng-click="ctrl.query()" type="submit" class="btn btn-cys btn-sm">
                            <span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <button ng-click="ctrl.reset()" type="reset" class="btn btn-default btn-sm">
                            <span class="glyphicon glyphicon-repeat"></span>
                            重置
                        </button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Search area END -->

    <!-- operation area -->
    <a type="button" class="btn btn-cys btn-sm" ng-click="ctrl.add()">
        <span class="glyphicon glyphicon-plus"></span>
        新增
    </a>
    <a type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/course/exportCourse')">
        <span class="glyphicon glyphicon-export"></span>
        批量删除
    </a>
    <div class="pull-right" ng-include="':root/components/page.html'"></div>
    <!-- operation area END -->
    <!-- data grid area -->
    <div style="padding-top: 10px;">
        <table class="table table-bordered table-hover table-striped">
            <tr>
                <th>
                    <input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox"/>
                </th>
                <th>工号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>出生日期</th>
                <th>年龄</th>
                <th>民族</th>
                <th>文化程度</th>
                <th>团干部</th>
                <th>团内职务</th>
                <th>操作</th>
            </tr>
            <tr ng-repeat="item in ctrl.entities.content">
                <td><input ng-model="item.$checked" type="checkbox"/></td>
                <td>{{item.xh}}</td>
                <td>{{item.xm}}</td>
                <td>{{item.xb.mc}}</td>
                <td>{{item.csrq}}</td>
                <td>{{item.nl}}</td>
                <td>{{item.mz.mc}}</td>
                <td>{{item.whcd.mc}}</td>
                <td>{{item.jztgb}}</td>
                <td>{{item.tnzw}}</td>
                <td>
                    <a href="javascript:;" ng-click="ctrl.edit(item)">编辑</a> <a href="javascript:;"
                                                                                ng-click="ctrl.del(item)">删除</a>
                </td>
            </tr>
        </table>
        <p>
            共有记录：
            <span>{{ctrl.entities.totalElements}}</span> 条
        </p>
    </div>
    <!-- data grid area END -->
    <div ng-non-bindable template class="hidden">
        <h3 class="panel-title" edit-title>
            <span class="glyphicon glyphicon-search"></span> 团干部管理
        </h3>
        <div edit>
            <div class="panel-body">
                <form class="form-horizontal" ng-if="result">
                    <div class="row">
                        <data bind-ctrl="ctrl.teachergh" auto-load="true" entity="Teacher">
                            <filter field="employeeNo" operator="like" value="'%'+result.teacher.employeeNo+'%'"/>
                        </data>
                        <data bind-ctrl="ctrl.teachername" auto-load="true" entity="Teacher">
                            <filter field="name" operator="like" value="'%'+result.teacher.name+'%'"/>
                        </data>
                        <div class="form-group">
                            <label class="col-md-2 control-label">工号:</label>
                            <div class="col-md-4">
                                <md-autocomplete md-no-cache="true" md-selected-item="result.teacher"
                                                 md-search-text="ctrl.ghSearchText"
                                                 md-search-text-change="ctrl.teachergh.setFilter('xh','%'+ctrl.ghSearchText+'%','like')"
                                                 md-items="item in ctrl.teachergh.queryPage()" md-item-text="item.employeeNo"
                                                 md-min-length="0" placeholder="输入学号搜索">
                                    <md-item-template>
                                        <span md-highlight-text="ctrl.ghSearchText"
                                              md-highlight-flags="^i">{{item.employeeNo}}</span>
                                    </md-item-template>
                                    <md-not-found>
                                        没有找到教师
                                    </md-not-found>
                                </md-autocomplete>
                                </td>
                            </div>
                            <label class="col-md-2 control-label">姓名:</label>
                            <div class="col-md-4">
                                <md-autocomplete md-no-cache="true" md-selected-item="result.teacher"
                                                 md-search-text="ctrl.nameSearchText"
                                                 md-search-text-change="ctrl.teachername.setFilter('name','%'+ctrl.nameSearchText+'%','like')"
                                                 md-items="item in ctrl.teachername.queryPage()" md-item-text="item.name"
                                                 md-min-length="0" placeholder="输入姓名搜索">
                                    <md-item-template>
                                        <span md-highlight-text="ctrl.nameSearchText" md-highlight-flags="^i">{{item.name}}</span>
                                    </md-item-template>
                                    <md-not-found>
                                        没有找到教师
                                    </md-not-found>
                                </md-autocomplete>
                                </td>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">性别:</label>
                            <div class="col-md-4">
                                <input ng-model="result.teacher.sexString" readonly="true"
                                       type="text" class="form-control">
                            </div>
                            <label class="col-md-2 control-label">出生日期:</label>
                            <div class="col-md-4 radio">
                                <input ng-model="result.teacher.birthDate" readonly="true"  datetimepicker
                                        type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">民族:</label>
                            <div class="col-md-4">
                                <input ng-model="result.teacher.ethnicGroup.name" readonly="true" name="result.teacher.ethnicGroup.name"
                                       type="text" class="form-control">
                                <input type=""hidden ng-model = "result.teacher.employeeNo" name="result.gh" />
                            </div>
                            <label class="col-md-2 control-label">文化程度:</label>
                            <div class="col-md-4">
                                <input ng-model="result.teacher.whcd.mc" name="result.teacher.whcd.mc" readonly="true"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">团干部:</label>
                            <div class="col-md-4">
                                <input switch-handle-width="80px" bs-switch type="checkbox" ng-model="result.tgb"
                                       switch-size="small" switch-on-text="专职" switch-off-text="兼职"
                                       name="result.tgb"/>
                            </div>
                            <label class="col-md-2 control-label">团内职务:</label>
                            <div class="col-md-4">
                                <input ng-model="result.tnzw" name="result.tnzw" placeholder="请输入团内职务" title="请输入团内职务"
                                       type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-md-2 control-label">备注:</label>
                            <div class="col-md-4">
                                <input ng-model="result.bz" name="result.bz"
                                       type="text" class="form-control">
                            </div>

                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>